import {defineStore} from "pinia";
import {ref} from "vue";
import {getAllUserAPI, getUserDetailByIdAPI} from "@/apis/userManage.js";


// export const useUserManageStore=defineStore('userManage',()=>{
//     // 1.定义用户信息数据state
//     const allUserInfo=ref({});
//
//
//     // 2.定义获取接口数据的action函数
//
//     const getAllUserInfo=async ({current,pageSize}:{current:number,pageSize:number})=>{
//
//         const res=await getAllUserAPI(current,pageSize);
//         allUserInfo.value=res.data;
//
//     }
//
//     return {
//         getAllUserInfo,allUserInfo
//     },
//         {
//             persist:true,
//         }
// })

export const useUserManageStore=defineStore('accountInfo',()=>{

        // 1.定义用户信息数据state
    const userListStore=ref([]);
    const userInfoStore=ref({});


    // 2.定义获取接口数据的action函数

    const getAllUserListStore=async (current:number,pageSize:number)=>{
        const res=await getAllUserAPI(current,pageSize);
        userListStore.value=res.data;
    }

    const getUserDetailByIdStore=async (id:number)=>{
        userInfoStore.value=await getUserDetailByIdAPI(id);
    }




        //3.以对象的格式把state和action return
        return {
            userListStore,getAllUserListStore,userInfoStore,getUserDetailByIdStore
        }
    },
    // pinia持久化配置，存入ls，true
    {
        persist:false,
    })
